﻿<navigation:Page x:Class="ScrumBoard.Views.Board" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           xmlns:ti="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"      
           xmlns:tc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
           xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           xmlns:local="clr-namespace:ScrumBoard"
           mc:Ignorable="d" Foreground="#4b5657"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Board Page" Loaded="Page_Loaded">
  
  <navigation:Page.Resources>
    <DataTemplate x:Key="TaskDataTemplate">
      <Grid Margin="5" Height="150" Width="150" MouseLeftButtonDown="Grid_MouseLeftButtonDown" Tag="task">
      	<Grid.Background>
      		<SolidColorBrush Color="{Binding Background}" />
				</Grid.Background>
        <TextBlock Text="{Binding Name}" Margin="5,5,5,30" Foreground="White" VerticalAlignment="Top" TextWrapping="Wrap"/>
				<TextBlock Text="{Binding TeamMember}" Margin="7" FontSize="16" FontWeight="SemiBold"  Foreground="White" VerticalAlignment="Bottom" />
				<TextBlock Text="{Binding EstimatedTime}" Margin="7,3" FontSize="30" Foreground="White" VerticalAlignment="Bottom" HorizontalAlignment="Right" />



        <ti:ContextMenuService.ContextMenu>
          <ti:ContextMenu>
            <ti:MenuItem Header="Edit" Click="EditTask_Click" />
            <ti:MenuItem Header="Remove" Click="RemoveTask_Click" />
          </ti:ContextMenu>
        </ti:ContextMenuService.ContextMenu>
      </Grid>
    </DataTemplate>

    <DataTemplate x:Key="TaskStateCellTemplate">
      <tc:WrapPanel Margin="5" Background="Transparent">
        <i:Interaction.Behaviors>
          <ei:FluidMoveBehavior AppliesTo="Children" Duration="0:0:0.3">
            <ei:FluidMoveBehavior.EaseY>
              <BackEase EasingMode="EaseOut" Amplitude="0.2"/>
            </ei:FluidMoveBehavior.EaseY>
            <ei:FluidMoveBehavior.EaseX>
              <BackEase EasingMode="EaseOut" Amplitude="0.2"/>
            </ei:FluidMoveBehavior.EaseX>
          </ei:FluidMoveBehavior>
          <local:ReorderBehavior ScopeRoot="{Binding RelativeSource={RelativeSource AncestorType=sdk:DataGridRow}}" Reordered="ReorderBehavior_Reordered" />
          <local:ChildrenGeneratorBehavior ItemTemplate="{StaticResource TaskDataTemplate}" ChildrenGenerating="Story_ChildrenGenerating" />
        </i:Interaction.Behaviors>
      </tc:WrapPanel>
    </DataTemplate>

    <DataTemplate x:Key="StoryCellTemplate">
    	<Grid Margin="5" Background="Transparent">   		
    		<Grid.RowDefinitions>
    			<RowDefinition Height="Auto" />
					<RowDefinition Height="*" MaxHeight="300" />	
					<RowDefinition  />
				</Grid.RowDefinitions>
				<TextBlock Text="{Binding Name}" TextWrapping="Wrap" FontWeight="SemiBold" />
				<TextBlock Text="{Binding Description}" TextWrapping="Wrap" Grid.Row="1" />
        <ContentControl Content="{Binding Comments.Count}" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="10" >
					<ContentControl.Template>
						<ControlTemplate TargetType="ContentControl">
				    	<Grid Width="21" Height="20" >
				    		<Path Data="M1,2 C1,1.4477153 1.4477153,1 2,1 L19.791666,1 C20.34395,1 20.791666,1.4477153 20.791666,2 L20.791666,13 C20.791666,13.552285 20.34395,14 19.791666,14 L13.308235,14 L10.724902,17.5 L8.2665691,14 L2,14 C1.4477153,14 1,13.552285 1,13 z" Stretch="Fill" Stroke="{StaticResource ImportantForeground}" StrokeThickness="2" Margin="0,2.5,-0.792,-1" UseLayoutRounding="False"/>
                <ContentPresenter  HorizontalAlignment="Center" Margin="0,3,0,0"  Content="{TemplateBinding Content}" />
				    	</Grid>
				    </ControlTemplate>
					</ContentControl.Template>
				</ContentControl>


        <ti:ContextMenuService.ContextMenu>
          <ti:ContextMenu>
            <ti:MenuItem Header="Edit" />
            <ti:MenuItem Header="Add Task" Click="AddTask_Click" />
          </ti:ContextMenu>
        </ti:ContextMenuService.ContextMenu>
      </Grid>
    </DataTemplate>
  </navigation:Page.Resources>
  
  <Grid x:Name="LayoutRoot" d:DataContext="{StaticResource MainVMSampleData}">

    <sdk:DataGrid ItemsSource="{Binding CurrentSprint.Stories}" CellStyle="{StaticResource TaskStateCellStyle}" IsReadOnly="True" 
			 Style="{StaticResource DataGridStyle1}" x:Name="datagrid">
      <sdk:DataGrid.Columns>
        <sdk:DataGridTemplateColumn Width="200" CellTemplate="{StaticResource StoryCellTemplate}" />
        <sdk:DataGridTemplateColumn Header="To Do"  Width="*" CellTemplate="{StaticResource TaskStateCellTemplate}"  />
        <sdk:DataGridTemplateColumn Header="In Progress"  Width="*" CellTemplate="{StaticResource TaskStateCellTemplate}"/>
        <sdk:DataGridTemplateColumn Header="To Validate" Width="*" CellTemplate="{StaticResource TaskStateCellTemplate}" />
        <sdk:DataGridTemplateColumn Header="Done" Width="*" CellStyle="{StaticResource TaskStateCellStyle}" CellTemplate="{StaticResource TaskStateCellTemplate}" />
      </sdk:DataGrid.Columns>
    </sdk:DataGrid>
  </Grid>
</navigation:Page>
